package jmine.tec.datadigester.positional.writer;

import jmine.tec.datadigester.positional.meta.PositionalStringFieldMetadata;

/**
 * {@link PositionalFieldWriter} para campos do tipo String
 * 
 * @author israel.crisanto
 */
public class StringPositionalFieldWriter extends AbstractPositionalFieldWriter<PositionalStringFieldMetadata> {

    /**
     * Construtor
     * 
     * @param fieldMetadata fieldMetadata
     */
    public StringPositionalFieldWriter(PositionalStringFieldMetadata fieldMetadata) {
        super(fieldMetadata);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Object read(String line) {
        PositionalStringFieldMetadata meta = this.getFieldMetadata();
        String data = line.substring(meta.start(), meta.start() + meta.size());
        return meta.shouldTrim() ? data.trim() : data;
    }
}
